package com.jiang.daily.Q642;

import java.util.List;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/02/19 15:22
 */
class Solution {
    public int maxDistance(List<List<Integer>> arrays) {
        int min = arrays.get(0).get(0), max = arrays.get(0).get(arrays.get(0).size() - 1);
        int res = 0;
        for (int i = 1; i < arrays.size(); i++) {
            int m = arrays.get(i).get(0);
            int n = arrays.get(i).get(arrays.get(i).size() - 1);
            if (Math.abs(max - m) > res) res = Math.abs(max - m);
            if (Math.abs(n - min) > res) res = Math.abs(n - min);
            if (m < min) min = m;
            if (n > max) max = n;
        }
        return res;
    }
}
